<?php
	session_start();
	$uid = $_SESSION['name'];
	include_once("global.php");	
	$smarty->assign("uid",$uid);
	//头部
	
	$sql_select_uid = "select U_Integral,U_Consume from userinfo where U_UID = '$uid'";
	$query_select_uid = $mysqli->query($sql_select_uid);
	$result_select_uid = $query_select_uid->fetch_assoc();
	$integral = $result_select_uid['U_Integral'];
	$consume = $result_select_uid['U_Consume'];
	$total = $integral-$consume;
	if($total<'24'){
		echo "<script>alert('积分不够你来抽奖的，赶紧去下应用赢积分吧！')</script>";
		echo "<meta http-equiv=\"refresh\" content=\"0; url='index.php' />";
	}else{
		$arr_1= array(
			'0' => array('id'=>1,'prize'=>'templates/images/ipad3.png','v'=>0),
			'1' => array('id'=>2,'prize'=>'templates/images/iPhone5.png','v'=>0),
			'2' => array('id'=>3,'prize'=>'templates/images/iPhone4s.png','v'=>0), 
			'3' => array('id'=>4,'prize'=>'templates/images/iPad2.png','v'=>0),
			'4' => array('id'=>5,'prize'=>'templates/images/iTouch5.png','v'=>0),
			'5' => array('id'=>6,'prize'=>'templates/images/iTouch4.png','v'=>0),
			'6' => array('id'=>7,'prize'=>'templates/images/50chongzhika.png','v'=>0),
			'7' => array('id'=>8,'prize'=>'templates/images/10yuanQB.png','v'=>0),
			'8' => array('id'=>9,'prize'=>'templates/images/30jifen.png','v'=>5),
			'9' => array('id'=>10,'prize'=>'templates/images/20jifen.png','v'=>10),
			'10' => array('id'=>11,'prize'=>'templates/images/15jifen.png','v'=>15),
			'11' => array('id'=>12,'prize'=>'templates/images/zaijiezaili.png','v'=>70),
		);
		shuffle($arr_1);
		for($a=0;$a<count($arr_1);$a++){
			$assign_arr[] = $arr_1[$a]['prize'];
		}
		$smarty->assign("assign_arr",$assign_arr);
	
		$sql_select_search = "select K_Name,K_KID from keywordinfo where K_search > '1' limit 0,4";
		$query_select_search = $mysqli->query($sql_select_search);
		while($result_select_search = $query_select_search->fetch_assoc()){
			$assign_search[] = array(	"num"	=>	$result_select_search['K_KID'],
										"name"	=>	$result_select_search['K_Name']);
		}
		$smarty->assign("assign_search",$assign_search);/*热门关键词*/
		
		$sql_select_skeyword = "select K_Name,K_KID from keywordinfo where K_search = '1'";
		$query_select_skeyword = $mysqli->query($sql_select_skeyword);
		while($result_select_skeyword = $query_select_skeyword->fetch_assoc()){
			$assign_skeyword[] = array(	"num"	=>	$result_select_skeyword['K_KID'],
										"name"	=>	$result_select_skeyword['K_Name']);
		}
		$smarty->assign("assign_skeyword",$assign_skeyword);/*搜索框内关键词*/
		
		$sql_select_articlecategory = "select * from categoryinfo limit 0,2";
		$query_select_articlecategory = $mysqli->query($sql_select_articlecategory);
		while($result_select_articlecategory = $query_select_articlecategory->fetch_assoc()){
			$assign_artcategory[] = array (	"id"	=>	$result_select_articlecategory['C_CID'],
											"name"	=>	$result_select_articlecategory['C_Categoryname']);
		}
		$smarty->assign("assign_artcategory",$assign_artcategory);/*导航条*/
		
		$sql_select_countapp = "select * from appinfo";
		$query_select_countapp = $mysqli->query($sql_select_countapp);
		$result_select_countapp = $query_select_countapp->num_rows;
		$assign_countapp = $result_select_countapp;
		$smarty->assign("assign_countapp",$assign_countapp);
		
		$random = rand(50,$assign_countapp);
		$assign_radnom = $random;
		$smarty->assign("assign_radnom",$assign_radnom);/*站内APP统计*/
		
		//通栏推广位
		$sql_select_banner = "select * from pushinfo where P_Pushid >30";
		$query_select_banner = $mysqli->query($sql_select_banner);
		while($result_select_banner = $query_select_banner->fetch_assoc()){
			$banner_appid = $result_select_banner['P_Pushappid'];
			$banner_apppid = $result_select_banner['P_Pushpid'];
			
			$sql_select_bannerpic = "select * from pictureinfo where P_PID = '$banner_apppid'";
			$query_select_bannerpic = $mysqli->query($sql_select_bannerpic);
			$result_select_bannerpic = $query_select_bannerpic->fetch_assoc();
			
			$sql_select_bannerapp = "select * from appinfo where A_Apptrackid = '$banner_appid'";
			$query_select_bannerapp = $mysqli->query($sql_select_bannerapp);
			$result_select_bannerapp = $query_select_bannerapp->fetch_assoc();
			
			$assign_bannerapp[] = array(	"id"	=>	$banner_appid,
											"name"	=>	$result_select_bannerapp['A_Apptrackname'],
											"url"	=>	"images/".$result_select_bannerpic['P_Name'].".png",);
		}
		$smarty->assign("assign_bannerapp",$assign_bannerapp);/*顶部通栏，首页通栏1，首页通栏2*/
		
		$sql_select_listpush = "select * from pushinfo where P_Pushid >22 and P_Pushid <31";
		$query_select_listpush = $mysqli->query($sql_select_listpush);
		while($result_select_listpush = $query_select_listpush->fetch_assoc()){
			$pushappid = $result_select_listpush['P_Pushappid'];
			$pushapppid = $result_select_listpush['P_Pushpid'];
			$sql_select_listpushapp = "select A_Apptrackname from appinfo where A_Apptrackid = '$pushappid'";
			$query_select_listpushapp = $mysqli->query($sql_select_listpushapp);
			$result_select_listpushapp = $query_select_listpushapp->fetch_assoc();
			$listpushname = $result_select_listpushapp['A_Apptrackname'];
			
			$sql_select_listpushpic = "select * from pictureinfo where P_PID = '$pushapppid'";
			$query_select_listpushpic = $mysqli->query($sql_select_listpushpic);
			$result_select_listpushpic = $query_select_listpushpic->fetch_assoc();
			$name = $result_select_listpushpic['P_Name'];
			
			$assign_listpush[] = array(	"id"	=>	$pushappid,
										"name"	=>	$listpushname,
										"path"	=>	"/images/".$name.".png",
										);
		}
		$smarty->assign("assign_listpush",$assign_listpush);
	}
	$sql_site_info = "select * from siteinfo";
	$query_site_info = $mysqli->query($sql_site_info);
	while($result_site_info = $query_site_info->fetch_assoc()){
		$assign_info[] = array(	"id"	=>	$result_site_info['S_SID'],
								"info"	=>	$result_site_info['S_Name'],
								);
	}
	$smarty->assign("assign_info",$assign_info);

		$smarty->display("lottery.html");
		$smarty->display("footer.html");
	

?>